#include "SemanticNodeBlockEnter.h"

/**
 *  @fn	SemanticNodeBlockEnter::SemanticNodeBlockEnter(const SyntaxTreeNode *enterNodeParent,
 *  	SemanticNode *parent)
 * 
 *  @brief	Constructor. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	enterNodeParent	If non-null, the advance node parent.
 *  @param	parent				If non-null, the parent.
 */
SemanticNodeBlockEnter::SemanticNodeBlockEnter(const SyntaxTreeNode *enterNodeParent, SemanticNode *parent) : SemanticNode(parent), LabeledNode(enterNodeParent->Nodes->GetData(0)) {
	unitNumber = (enterNodeParent->Nodes->GetData(1)->Nodes->GetData(0)->Nodes->GetData(1)->Nodes->GetCount() > 0);
	queue = (enterNodeParent->Nodes->GetData(1)->Nodes->GetData(0)->Nodes->GetData(3)->Nodes->GetCount() > 0);
}
/**
 *  @fn	bool SemanticNodeBlockEnter::hasUnitNumber(void)
 * 
 *  @brief	Query if this object has unit number. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @return	true if unit number, false if not.
 */
bool SemanticNodeBlockEnter::hasUnitNumber(void) {
	return unitNumber;
}
/**
 *  @fn	bool SemanticNodeBlockEnter::hasQueue(void)
 * 
 *  @brief	Query if this object has queue. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @return	true if queue, false if not.
 */
bool SemanticNodeBlockEnter::hasQueue(void) {
	return queue;
}
/**
 *  @fn	void SemanticNodeBlockEnter::setUnitNumber(SemanticNodeExpression *unitNo)
 * 
 *  @brief	Sets the unit number. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 */
void SemanticNodeBlockEnter::setUnitNumber(SemanticNodeExpression *unitNo) {
	unitNumberExpression = unitNo;
}
/**
 *  @fn	void SemanticNodeBlockEnter::setStorage(SemanticNodeExpression *storageSet)
 * 
 *  @brief	Sets the storage. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 */
void SemanticNodeBlockEnter::setStorage(SemanticNodeExpression *storageSet) {
	storageExpression = storageSet;
}
/**
 *  @fn	void SemanticNodeBlockEnter::setQueue(SemanticNodeExpression *queueSet)
 * 
 *  @brief	Sets the queue. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 */
void SemanticNodeBlockEnter::setQueue(SemanticNodeExpression *queueSet) {
	queueExpression = queueSet;
}
/**
 *  @fn	std::string SemanticNodeBlockEnter::toDebugString(int tab)
 * 
 *  @brief	Converts a tab to a debug string. 
 * 
 *  @author	Nikola Novak
 *  @date	6/25/2009
 * 
 *  @param	tab	The tab.
 * 
 *  @return	This object as a std::string.
 */
std::string SemanticNodeBlockEnter::toDebugString(int tab) {
	std::ostringstream res;
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	res << getLabelsDebugString() << ": enter ";
	if (!unitNumber) res << "1 ";
	else {
		res << std::endl << ((SemanticNode *)unitNumberExpression)->toDebugString(tab + 1);
		for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	}
	res << "units in" << std::endl << ((SemanticNode *)storageExpression)->toDebugString(tab + 1);
	for (int i = 0; i < tab; i++)	res << DEBUG_STRING_RAZMAK;
	if (!queue) res << "forming implicit Queue" << std::endl;
	else {
		res << "forming" << std::endl << ((SemanticNode *)queueExpression)->toDebugString(tab + 1);
	}
	return res.str();
}
